home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 17 / CU Amiga Magazine's Super CD-ROM 17 (1997)(EMAP Images)(GB)[!][issue 1997-12].iso / CUCD / Programming / DiceSource / lib / fd / getfh.c < prev    next >
C/C++ Source or Header  |  1997-09-09  |  673b  |  39 lines

  1.  
  2.  
  3. /*
  4.  *  GETFH.C
  5.  *
  6.  *    (c)Copyright 1992-1997 Obvious Implementations Corp.  Redistribution and
  7.  *    use is allowed under the terms of the DICE-LICENSE FILE,
  8.  *    DICE-LICENSE.TXT.
  9.  */
  10.  
  11. #include <stdio.h>
  12. #include <fcntl.h>
  13. #include <errno.h>
  14.  
  15. _IOFDS *
  16. __getfh(ifd)
  17. int ifd;
  18. {
  19.     _IOFDS *d;
  20.     short fd = ifd;
  21.  
  22.     if(ifd == (int)stdin)d = &_IoStaticFD[0];
  23.     else if (ifd == (int)stdout)d = &_IoStaticFD[1];
  24.     else if (ifd == (int)stderr)d = &_IoStaticFD[2];
  25.     else if ((unsigned)fd >= _IoFDLimit) {
  26.     errno = EBADF;
  27.     return(NULL);
  28.     }
  29.     else d = _IoFD + fd;
  30.  
  31.     if ((d->fd_Flags & O_ISOPEN) == 0) {
  32.     errno = EBADF;
  33.     return(NULL);
  34.     }
  35.     return(d);
  36. }
  37.  
  38.  
  39.